﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Identity;
using WeChat.CMS.Controllers;

namespace WeChat.CMS.OrganizationUnits
{

    [Authorize]
    [RemoteService(Name = "OrganizationUnit")]
    [ControllerName("OrganizationUnit")]
    [Route("api/identity/organizationUnit")]
    public  class OrganizationUnitController:CMSController
    {
        private IOrganizationUnitAppService _organizationUnitAppService;
        public OrganizationUnitController(IOrganizationUnitAppService organizationUnitAppService)
        {
            _organizationUnitAppService = organizationUnitAppService;
            //IOrganizationUnitAppService organizationUnitAppService
        }

        [HttpPost]
        public async Task<bool> CreateAsync(OrganizationUnitCreateDto input)
        {
            return await _organizationUnitAppService.CreateAsync(input);
        }

        [HttpDelete]
        [Route("{id}")]
        public async Task<bool> DeleteAsync(Guid id)
        {
            return await _organizationUnitAppService.DeleteAsync(id);
        }
        [HttpGet]
        [Route("all")]
        public async Task<List<OrganizationUnitTreeDto>> GetAllListAsync()
        {
            return await _organizationUnitAppService.GetAllListAsync();
        }

        [HttpGet]
        public async Task<OrganizationUnitEto> GetOrganizationById(Guid orgId)
        {
            return await _organizationUnitAppService.GetOrganizationById(orgId);
        }

        [HttpGet]
        [Route("orgForCommunityTree")]
        public async Task<List<OrganizationUnitTreeDto>> GetOrganizationUnitForCommuityTreeAsync(Guid userId)
        {
            return await _organizationUnitAppService.GetOrganizationUnitForCommuityTreeAsync(userId);
        }

        [HttpGet]
        [Route("orgForTree")]
        public async Task<List<OrganizationUnitTreeDto>> GetOrganizationUnitForTreeAsync(Guid? parnet)
        {
            return await _organizationUnitAppService.GetOrganizationUnitForTreeAsync(parnet);
        }
        [HttpGet]
        [Route("orglistbyuserid")]
        public async Task<List<OrganizationUnitTreeDto>> GetOrgListByUserIdAsync(Guid userid)
        {
            return await _organizationUnitAppService.GetOrgListByUserIdAsync(userid);
        }

        [HttpPut]
        [Route("move")]
        public async Task MoveAsync(MoveOrganizationUnitDto input)
        {
            await _organizationUnitAppService.MoveAsync(input);
        }

        [HttpPut]
        public async Task<bool> UpdateAsync(OrganizationUnitUpdateDto input)
        {
            return await _organizationUnitAppService.UpdateAsync(input);
        }
        [HttpGet]
        [Route("org-unbind-user")]
        public async Task<PagedResultDto<IdentityUserDto>> GetUnAddUsersAsync(OrganizationUnBindUseRequestDto request)
        {
            return await _organizationUnitAppService.GetUnAddUsersAsync(request);
        }
    }
}
